﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Common
{
    public class FileHelper
    {

        #region 创建HTML文件
         
        /// <summary>
        /// 创建HTML文件
        /// </summary>
        /// <param name="paths">文件所在路径(多路径的)</param>
        /// <param name="content">文件中的内容</param>
        /// <param name="coding">文件所使用的编码(ex:gbk|utf-8)</param>
        /// <create>zhangjj</create>
        /// <createTime>20080218</createTime>
        public static void CreateHTML(string paths, string content, string coding)
        {
            string[] pathArray = paths.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);// BuildMultiPath(multiRoot, subPath);
            foreach (string path in pathArray)
            {
                if (!File.Exists(path))
                {
                    FileInfo fi = new FileInfo(path);
                    if (!Directory.Exists(fi.DirectoryName))
                    {
                        Directory.CreateDirectory(fi.DirectoryName);
                    }
                    FileStream rs = File.Create(path);
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(rs, System.Text.Encoding.GetEncoding(coding));
                    sw.Write(content);
                    sw.Close();
                }
                else
                {
                    FileStream rs = File.Open(path, FileMode.Create);
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(rs, System.Text.Encoding.GetEncoding(coding));
                    sw.Write(content);
                    sw.Close();
                }
            }
        }

         
        #endregion
    }
}
